package com.yueguang.springai.config;

import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class ArkServiceConfig {

    @Value("${spring.ai.openai.api-key}")
    private String apiKey;

    @Bean
    public ConnectionPool connectionPool() {
        return new ConnectionPool(5, 1, TimeUnit.SECONDS);
    }

    @Bean
    public Dispatcher dispatcher() {
        return new Dispatcher();
    }

    @Bean
    public ArkService arkService(ConnectionPool connectionPool, Dispatcher dispatcher) {
        return ArkService.builder()
                .dispatcher(dispatcher)
                .connectionPool(connectionPool)
                .baseUrl("https://ark.cn-beijing.volces.com/api/v3")
                .apiKey(apiKey)
                .build();
    }
}

